package com.stenio.fancat.controller.user;

import com.stenio.fancat.controller.Result;
import com.stenio.fancat.exception.FanCatException;
import com.stenio.fancat.form.user.UserPraiseForm;
import com.stenio.fancat.service.user.UserPraiseService;
import com.stenio.fancat.vo.UserPraiseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("userPraise")
public class UserPraiseController {

    @Autowired
    private UserPraiseService userPraiseService;

    @PostMapping("/insertPraise")
    public Result<UserPraiseVO> insertPraise(@RequestBody UserPraiseForm userPraiseForm){
        Result<UserPraiseVO> result = new Result<>();
        try {
            result.setData(userPraiseService.insertPraise(userPraiseForm));
        } catch (FanCatException e) {
            result.setMsg(e.getMessage());
            result.setFlag(Result.FLAG.failure);
            return result;
        }
        result.setFlag(Result.FLAG.success);
        return result;
    }
}
